---
title: Count pages
summary: Estimates the page count by scanning raw PDF markup.
status: draft
owner: SAIF Doc Gen
last_reviewed: 2026-09-17
library: PdfAPI.Core
reference_type: package
operation_id: OP-05
trigger: PdfClientService.GetPageCount(byte[]) invoked
---

# Count pages

This operation counts pages by scanning decoded PDF markup for `/Type /Page` markers, rather than parsing the PDF object graph.

| Field | Value |
| --- | --- |
| **Operation ID** | OP-05 |
| **Trigger** | Caller invokes `GetPageCount(byte[] file)` |
| **Inputs** | PDF bytes |
| **Outputs** | Integer page count |
| **Primary components** | `PdfAPI.Core.PdfClientService.GetPageCount`, `FindPageCount` |
| **Entry point** | `PdfAPI.Core\Services\PdfClientService.cs` |

## Steps

1. Run [Validate PDF bytes](op-01-validate-pdf-bytes.md) to guard the input. ([BR-01](../business-rules.md#br-01-pdf-signature-validation), [BR-02](../business-rules.md#br-02-null-bytes-are-never-a-pdf), [BR-03](../business-rules.md#br-03-invalid-pdf-input-aborts-with-pdfexception))
2. Decode the bytes as UTF-8 into a string.
3. Count regex matches of `/Type\s*/Page[^s]` in the decoded markup and return the count. ([BR-09](../business-rules.md#br-09-page-count-via-marker-scan))
   - If the decoded text is null: return `0`.

## Process flow

The following diagram visualizes this operation's control flow.

```mermaid
flowchart TD
	Start(["GetPageCount(bytes)"]) --> Guard["OP-01: ValidatePdf"]
	Guard --> Decode["Decode UTF-8"]
	Decode --> Count["Count /Type /Page<br>regex matches"]
	Count --> Return([Return integer count])
```

## Failure and edge-case behavior
- This counts page objects by scanning raw markup rather than parsing the PDF object graph, so compressed object streams or a `/Type /Page` token inside a content stream can skew the count.*

> **Note:** Statements marked with `*` were inferred from code structure, naming
> conventions, or contextual evidence where direct confirmation was not available
> in source artifacts.

## Related documentation
- [Operations and processes](../operations-processes.md)
- [Business rules](../business-rules.md)
- [Security and authorization](../security-authorization.md)

## Sources
- `PdfAPI.Core\Services\PdfClientService.cs`
